<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <title>版本浏览</title>
    <link href="/static/css/start/jquery-ui-1.10.4.custom.css" rel="stylesheet">
    <link href="/static/css/box.css" rel="stylesheet">
    <link href="/static/css/table.css" rel="stylesheet">
    <link href="/static/css/pages.css" rel="stylesheet">
    <script src="/static/js/jquery-1.10.2.js"></script>
    <script src="/static/js/jquery-ui-1.10.4.custom.js"></script>
    <script src="/static/js/helper.js"></script>
    <script src="/static/js/pages.js"></script>
    <style>
        .branch_line {
            background-color: #acdd4a;
        }

        .subbranch_line {
            background-color: #9DADC5;
        }

        .branch {
            word-break: keep-all;
            white-space: nowrap;
        }

        .subbranch {

            padding-left: 10px;
            word-break: keep-all;
            white-space: nowrap;
        }

        .version {
            padding-left: 20px;
            word-break: keep-all;
            white-space: nowrap;
        }

        .highlight {
            background-color: #e14f1c;
            color: #ffffff;
        }

        .accessed {
            color: green;
        }

        .noaccessed {
            color: red;
        }

    </style>
    <script>
        var pageIndex ={{ p }};
        var pageCount ={{ page_count }};
        var versionsData = [];
        var isToday = false;

        function highlight(obj) {

            var text = $(obj).text().trim();
            $(".highlight").removeClass("highlight");
            if (text) {
                $("td:contains('" + text + "')").addClass("highlight");
            }
        }

        function clear_highlight(obj) {
            $(".highlight").removeClass("highlight");
        }

        function enterKeyLoadVersions(event) {
            if (event.which == 13) {
                $('form').submit();
            }
        }

        function toPage(index) {
            pageIndex = index;
            window.location.search = 'p=' + index;
        }
        function checkWebAccess(fullName, ctrl) {
            //alert(fullName);
            var url = '/check_web_access/' + fullName;
            $.post(url, {},
                    function (result, status) {
                        if (status == 'success') {
                            if (result.success) {
                                if (result.result) {
                                    ctrl.after('<div class="accessed" >外网已访问</div>');
                                }
                                else {
                                    ctrl.after('<div class="noaccessed" >外网未访问</div>');
                                }
                            }
                        }

                    });
        }
        function getDownloadUrl() {
            $('a[getd]').each(function () {
                var ctrl = $(this);
                var fullName = ctrl.text();
                $.post('/downloadUrl/' + fullName, {},
                        function (result, status) {
                            if (status == 'success') {
                                if (result.success) {
                                    ctrl.attr("href", result.result);
                                    ctrl.text(fullName);
                                    checkWebAccess(fullName, ctrl);
                                }
                                //ctrl.attr("href",'http://www.baidu.com');
                            }
                        });
            });

        }
        $(function () {
            $('.mybutton').button();
            $('#keyword').keydown(enterKeyLoadVersions);
            showSplitPages();
            //loadVersions(false);
            getDownloadUrl();
        });
        function setToday() {
            $('input[name=today]').val('true');
            return true;
        }
    </script>
</head>
<body>
<h1 style="text-align: center" class="ui-dialog-titlebar">版本浏览
    {% if today %}
        <span style="font-size: small"> (今日版本)</span>
    {% endif %}
</h1>

<div style="text-align: right">
    <a href="main.py">管理</a><br/>
    <a href="log.py">发布记录</a>
</div>

<hr>
<form action="browseVersion.py" method="post">
    <div style="text-align: center">

        <input type="hidden" name="today">
        <input type="text" id="keyword" name="keyword" value="{{ keyword }}" style="width: 60%;">
        {% if today %}
            <input type="submit" class="mybutton" style="font-size: 13px;" value="查找所有">
        {% else %}
            <input type="submit" class="mybutton" style="font-size: 13px;" value="查找">
            <input type="submit" class="mybutton" style="font-size: 13px;" onclick="setToday();" value="查找今日版本">
        {% endif %}
    </div>
</form>
<table border="1" style="width: 100%">
    <thead>
    <th>版本号</th>
    <th>时间</th>
    <th>用户名</th>
    <th>说明</th>
    </thead>
    <tbody id="versionsData">
    {% for i in result %}
        {% ifequal i.type 'branch' %}
            <tr class="branch_line">
                <td colspan="3" class="branch">
                    {{ i.branch_name }}
                </td>
                <td>
                    {{ i.branch_desc }}
                </td>
            </tr>
        {% endifequal %}

        {% ifequal i.type 'subbranch' %}
            <tr class="subbranch_line">
                <td colspan="3" class="subbranch">
                    {{ i.subbranch_name }}
                </td>
                <td>
                    {{ i.subbranch_desc }}
                </td>
            </tr>
        {% endifequal %}

        {% ifequal i.type 'version' %}
            <tr>
                <td class="version">
                    <a getd>{{ i.version_fullname }}</a>

                </td>
                <td class="nowrap">{{ i.time|date:'Y-m-d H:i:s' }}</td>
                <td class="nowrap">
                    {% if i.version_username %}
                        {{ i.version_username }}
                    {% else %}
                        &nbsp;
                    {% endif %}
                </td>
                <td>
                    {{ i.version_desc|escape|linebreaks }}
                </td>
            </tr>
        {% endifequal %}

    {% endfor %}
    </tbody>
</table>
<div class="digg" id="pages">
</div>
</body>
</html>